import { request } from './requestzlb';
const preUrl = '/nkdisabled';

const bIsDtDreamAppLoginUrl = `https://puser.zjzwfw.gov.cn/sso/mobile.do?action=oauth&scope=1&servicecode=BCDSGA_a1e31eade0394804f43f6bbee9619bf7&redirectUrl=https://mapi.zjzwfw.gov.cn/web/mgop/gov-open/zj/2001826388/lastTest/index.html`
const bIsAlipayMiniLoginUrl = `https://puser.zjzwfw.gov.cn/sso/alipay.do?action=ssoLogin&citycod=&servicecode=BCDSGA_a1e31eade0394804f43f6bbee9619bf7&redirectUrl=https://mapi.zjzwfw.gov.cn/web/mgop/gov-open/zj/2001826388/lastTest/index.html`

//单点登录 重定向
export function getLoginParams() {
  
  const sUserAgent = window.navigator.userAgent.toLowerCase()
  // 浙里办APP
  const bIsDtDreamApp = sUserAgent.indexOf('dtdreamweb') > -1
  // 浙里办支付宝小程序
  const bIsAlipayMini = sUserAgent.indexOf('miniprogram') > -1 && sUserAgent.indexOf('alipay') > -1
  if (bIsAlipayMini) {
    window.location.href = bIsAlipayMiniLoginUrl
  } else {
    window.location.href = bIsDtDreamAppLoginUrl  
  }
}


export function watchApp() {
  window.onpageshow = (event) => {
    if (event.persisted || (window.performance && window.performance.navigation.type == 2)) {
      ZWJSBridge.close();
    }
    getLoginParams();
  }
}

export function watchApply() {
  window.onpageshow = (event) => {
    if (event.persisted || (window.performance && (window.performance.navigation.type == 1 ||
      window.performance.navigation.type == 0))) {
        getLoginParams();
    } else {
      my.navigateBack();
    }
  }
}



//上传 ticket和servicecode
export function setLoginParams(query:any) {
  return request({
    url: `mgop.zjyd.nkzc.getUser`,
    method:'GET',
    data: query,
  })
}

//我的证件信息包含详情：
export function getCertInfoApi() {
  return request({
    method:'GET',
    url: `mgop.zjyd.nkzc.certInfo`,
  })
}

//我的办事  status：0 全部 1 办理中 2 已办结
export function getErrandListApi(query:any) {
  return request({
    url: `mgop.zjyd.nkzc.errandList`,
    method:'GET',
    data:query
  })
}


//微信登录
export function weChatLoginApi(query) {
  return request({
    url: `mgop.zjyd.nkzc.getWechatUser`,
    method:'GET',
    data:query
  })
}